<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
echo "<response>";
session_start();
if ($_SESSION['kteam_auth'] != true)
{
    $expire=time()+60*60;
    setcookie("redirector", "producer.html", $expire);
    echo "<result>Login</result>";
    echo "</response>";
    //header("Location: login.html");
    exit;
}

include("sqlconnect.php");
include("sqlgenerator.php");
$debug = false;

if ($debug) {
    echo '<debug>';
    echo 'Post parameters: ' . $_GET['producer_code'];
    echo '</debug>';
}

$producer_code = $_GET['producer_code'];
$action = $_GET['action'];

if (!is_null($action) && $action=='delete') {
    db_connect();
    $query = delete_producer($producer_code);
    if ($debug) {
        echo '<debug>';
        echo 'Query: ' . $query;
        echo '</debug>';
    }

    $result = db_query($query);
    echo "<result>Deleted</result>";
    exit;
}

db_connect();

// Query the film details from the film code
if (is_null($producer_code)) {
    $query = get_all_producers();
} else {
    $query = get_producer($producer_code);
}
if ($debug) {
    echo '<debug>';
    echo 'Query: ' . $query;
    echo '</debug>';
}
$result = db_query($query);
if ($debug) {
    echo '<debug>';
    echo 'Query Result: ' . $result;
    echo '</debug>';
}

while ($row = mysql_fetch_array($result)) {
    echo '<producer>';
    try {
        echo '<producer_id>'.$row['id'].'</producer_id>';
        echo '<producer_name>'.$row['name'].'</producer_name>';
        echo '<producer_code>'.$row['code'].'</producer_code>';
        echo '<phone>'.$row['phone'].'</phone>';
        echo '<address>'.$row['address'].'</address>';
        echo '<banner_name>'.$row['banner_name'].'</banner_name>';
        echo '<password>'.$row['password'].'</password>';
        echo '<remarks>'.$row['remarks'].'</remarks>';
    } catch (Exception $e) {
        echo '</producer>';
        echo "<result>Error</result>";
        echo "</response>";
    }
    echo '</producer>';
}
echo "<result>Success</result>";
echo "</response>";

?>